package cn.anc.aonicardv.module.adpter.recorder;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;
import cn.anc.aonicardv.R;
import cn.anc.aonicardv.R2;
import cn.anc.aonicardv.util.StringUtils;

/**
 * Created by yangdai on 2017/6/20.
 */

public class RtspLogAdapter extends RecyclerView.Adapter {

    private List<String> mLogList  = new ArrayList<>();
    private Context mContext;

    public RtspLogAdapter(Context context) {
        this.mContext = context;
    }

    public void setData(List<String> mList) {
            mLogList.clear();
        mLogList.addAll(mList);
        notifyDataSetChanged();
    }

    public String getItem(int position) {
        if (null != mLogList && position < mLogList.size()) {
            return mLogList.get(position);
        }
        return null;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_log_rtsp, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        ViewHolder viewHolder = (ViewHolder) holder;
        final String simpleBean = mLogList.get(position);
        if (StringUtils.isEmptyOrNull(simpleBean)) {
            return;
        }
        viewHolder.logTv.setTextColor(mContext.getResources().getColor(R.color.com_background4));
        viewHolder.logTv.setText(simpleBean+"");

    }


    @Override
    public int getItemCount() {
        return mLogList == null ? 0 : mLogList.size();
    }


    public class ViewHolder extends RecyclerView.ViewHolder {

        @BindView(R2.id.tv_log)
        TextView logTv;
        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
